﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Payment
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="full-content">
    <h2>Credit Card Payment</h2>
    
    <div id="error"></div>
    <% using (Html.BeginForm("payment", "register"))
       {
    %>
    <table>
    <tr>
            <td>
                First Name On Card
            </td>
            <td>
                <%=Html.TextBox("firstname")%>
            </td>
            
        </tr>
        <tr>
            <td>
                Last Name On Card
            </td>
            <td>
                <%=Html.TextBox("lastname")%>
            </td>
        </tr>
        <tr>
            <td>
                Billing Address
            </td>
            <td>
                <%=Html.TextBox("address")%>
            </td>
        </tr>
        <tr>
            <td>
                Billing City
            </td>
            <td>
                <%=Html.TextBox("city")%>
            </td>
        </tr>
        <tr>
            <td>
                Billing State
            </td>
            <td>
                <%=Html.TextBox("state")%>
            </td>
        </tr>
        <tr>
            <td>
                Billing Zipcode
            </td>
            <td>
                <%=Html.TextBox("zipcode")%>
            </td>
        </tr>
        <tr>
            <td>
                Phone
            </td>
            <td>
                <%=Html.TextBox("phone")%>
            </td>
        </tr>
        <tr>
            <td>
                Credit Card Number
            </td>
            <td>
                <%=Html.TextBox("ccnumber")%>
            </td>
        </tr>
        
        <tr>
            <td>
                Expired Date
            </td>
            <td>
                <%=Html.TextBox("expirationdate")%>
            </td>
        </tr>
        
        <tr>
            <td>
                <h2>Total</h2>
            </td>
            <td>
                <h2>$<%=Session["Total"].ToString()%></h2>
                <input type="hidden" value="<%=Session["Total"].ToString()%>" name="amount" />
            </td>
        </tr> 
        <tr>
            <td>
                <input type="submit" value="Pay" id="Pay" onclick="return DoAjaxSubmit(this);" />
            </td>
        </tr>       
    </table>
    </div>
    <script type="text/javascript">
       function DoAjaxSubmit(btnClicked) {
           var form = $(btnClicked).parents('form');
           if ($("#firstname").val() == "" || $("#lastname").val() == "" ||
           $("#address").val() == "" || $("#city").val() == "" ||
           $("#state").val() == "" || $("#zip").val() == "" ||
           $("#phone").val() == "" || $("#ccnumber").val() == "" ||
           $("#expirationdate").val() == "") {
               $("#error").html("Please complete all fields");
               return false;
           }
           else {
               $("#error").html("");
              $.ajax({
                  type: "POST",
                  url: form.attr('action'), //'<%=ResolveUrl("~/register/go") %>',
                  data: form.serialize(),
                  error: function (xhr, status, error) {
                  },
                  success: function (response) {
                      if (response != null) {
                          if (!response.Successful) {
                              $("#error").html("An error occurred: " + response.Exception);
                              return false;
                          }
                          else {
                              window.location.href = "/Register/Receipt";
                          }
                      }
                  }
              });
           }
           return false;
       }
    </script>
    <%} %>
</asp:Content>
